package com.ss.android.newmedia.message;

import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.Pair;
import com.bytedance.common.plugin.interfaces.pushmanager.PushCommonConstants;
import com.bytedance.common.plugin.interfaces.pushmanager.setting.PushSetting;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.newmedia.BaseApplication;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public final class s {
    private static boolean a;
    private static boolean b;

    static {
        s.a = false;
        s.b = false;
    }

    public static Map a(Context arg5) {
        int v4 = 10;
        HashMap v1 = new HashMap();
        PushSetting.getInstance().getSSIDs(((Map)v1));
        HashMap v2 = new HashMap();
        Object v0 = v1.get(PushCommonConstants.KEY_INSTALL_ID);
        if(!android.support.design.a.isTextEmpty(((String)v0))) {
            v2.put("iid", v0);
        }

        v0 = v1.get(PushCommonConstants.KEY_DEVICE_ID);
        if(!android.support.design.a.isTextEmpty(((String)v0))) {
            v2.put("device_id", v0);
        }

        String v0_1 = android.support.design.a.doGetNetworkAccessType(android.support.design.a.getNetworkType(arg5));
        if(!android.support.design.a.isTextEmpty(v0_1)) {
            v2.put("ac", v0_1);
        }

        v0_1 = BaseApplication.getApplication().getTweakedChannel();
        if(v0_1 != null) {
            v2.put("channel", v0_1);
        }

        v2.put("aid", String.valueOf(BaseApplication.getApplication().getAid()));
        v0_1 = BaseApplication.getApplication().getAppName();
        if(v0_1 != null) {
            v2.put("app_name", v0_1);
        }

        v2.put("version_code", String.valueOf(BaseApplication.getApplication().getVersionCode()));
        v2.put("version_name", BaseApplication.getApplication().getVersion());
        v2.put("device_type", Build.MODEL);
        v2.put("device_brand", Build.BRAND);
        v2.put("language", Locale.getDefault().getLanguage());
        v2.put("os_api", String.valueOf(Build.VERSION.SDK_INT));
        try {
            v0_1 = Build.VERSION.RELEASE;
            if(v0_1 != null && v0_1.length() > v4) {
                v0_1 = v0_1.substring(0, 10);
            }

            v2.put("os_version", v0_1);
        }
        catch(Exception v0_2) {
        }

        v0 = v1.get(PushCommonConstants.KEY_OPENUDID);
        if(!android.support.design.a.isTextEmpty(((String)v0))) {
            v2.put("openudid", v0);
        }

        int v0_3 = UIUtils.getDensityDpi(arg5);
        if(v0_3 > 0) {
            v2.put("dpi", String.valueOf(v0_3));
        }

        v2.put("rom", s.c());
        v2.put("os", "android");
        v2.put("package", arg5.getPackageName());
        return ((Map)v2);
    }

    public static String a(String arg5, Map arg6) {
        ArrayList v1 = new ArrayList();
        if(arg6 != null) {
            Iterator v2 = arg6.entrySet().iterator();
            while(v2.hasNext()) {
                Object v0 = v2.next();
                ((List)v1).add(new Pair(((Map.Entry)v0).getKey(), ((Map.Entry)v0).getValue()));
            }
        }

        StringBuilder v0_1 = new StringBuilder(arg5);
        if(arg5.indexOf(63) < 0) {
            v0_1.append("?");
        }
        else {
            v0_1.append("&");
        }

        v0_1.append(android.support.design.a.a(((List)v1), "UTF-8"));
        return v0_1.toString();
    }

    private static String a(String arg7) {
        Throwable v1_1;
        String v0_1 = null;
        Throwable v6;
        BufferedReader v2 = null;
        String v1 = null;
        try {
            v2 = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("getprop " + arg7).getInputStream()), 1024);
            v0_1 = v2.readLine();
            return v0_1;
        } catch(Throwable v0) {
            Logger.e("ToolUtils", "Unable to read sysprop " + arg7, v0);
        }finally {
            if(v2 != null){
                try{
                    try {
                        v2.close();
                    } catch(IOException v1_2) {
                        Logger.e("ToolUtils", "Exception while closing InputStream", ((Throwable)v1_2));
                    }
                }catch (Exception e){

                }
            }
        }
        return v0_1;
    }

    private static boolean a() {
        boolean v0 = false;
        try {
            if((android.support.design.a.isTextEmpty(Build.BRAND)) || !Build.BRAND.toLowerCase().startsWith("huawei")) {
                if(android.support.design.a.isTextEmpty(Build.MANUFACTURER)) {
                    return v0;
                }
                else if(!Build.MANUFACTURER.toLowerCase().startsWith("huawei")) {
                    return v0;
                }
            }
        }
        catch(Throwable v1) {
            return v0;
        }

        return true;
    }

    private static boolean b() {
        if(!s.b) {
            try {
                if(Class.forName("miui.os.Build") == null) {
                }else {
                    s.a = true;
                    s.b = true;
                    boolean v0_1 = s.a;
                    return v0_1;
                }
            }
            catch(Exception v0) {
            }
            s.b = true;
        }

        return s.a;
    }

    private static String c() {
        int v2_1;
        String v2;
        String v3;
        int v0 = 1;
        StringBuilder v4 = new StringBuilder();
        try {
            if(s.b()) {
                v4.append("MIUI-");
            }
            else if(ToolUtils.c()) {
                v4.append("FLYME-");
            } else {
                v3 = s.a("ro.build.version.emui");
                if(TextUtils.isEmpty(((CharSequence)v3))) {
                    v2 = s.a("ro.build.version.emui");
                } else {
                    v2 = v3;
                }
                if(!TextUtils.isEmpty(((CharSequence)v2)) && (v2.toLowerCase().startsWith("emotionui"))) {
                    v2_1 = 1;
                } else if(s.a()) {
                    v2_1 = 1;
                } else {
                    v2_1 = 0;
                }
                if(v2_1 != 0) {
                    if(!"angler".equals(Build.BOARD)) {
                        v0 = 0;
                    }
                    else if(Build.MODEL == null) {
                        v0 = 0;
                    }
                    else if(!Build.MODEL.toLowerCase().contains("nexus")) {
                        v0 = 0;
                    }
                    else if(!Build.MODEL.toLowerCase().contains("6p")) {
                        v0 = 0;
                    }

                    if(v0 == 0) {
                        v4.append("EMUI-");
                    }
                }
                if(!TextUtils.isEmpty(((CharSequence)v3))) {
                    v4.append(v3).append("-");
                }
            }

            v4.append(Build.VERSION.INCREMENTAL);
        } catch(Throwable v0_1) {

        }
        return v4.toString();
    }
}

